package com.qfedu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.dao.AskforleaveDao;
import com.qfedu.entity.Askforleave;
import com.qfedu.entity.ResponseData;
import com.qfedu.service.AskforleaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AskforleaveServiceImpl implements AskforleaveService {
    @Autowired
    private AskforleaveDao askforleaveDao;


    @Override
    public boolean addAskforleave(Askforleave askforleave) {
        int i = askforleaveDao.addAskforleave(askforleave);
        if(i > 0){
            return true;
        }
        return false;
    }

    @Override
    public ResponseData<List<Askforleave>> findAllAskforleave(int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Askforleave>askforleaveList= askforleaveDao.findAllAskforleave();
        PageInfo pageInfo = new PageInfo(askforleaveList);

        int count =(int) pageInfo.getTotal();
        ResponseData<List<Askforleave>> responseData = new ResponseData<>();

        responseData.setCode(0);
        responseData.setData(askforleaveList);
        responseData.setCount(count);
        responseData.setMsg("ok");

        return responseData;
    }

    @Override
    public boolean deleteAskforleave(int id) {
        int i = askforleaveDao.deleteAskforleave(id);
        if(i > 0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateAskforleave(Askforleave askforleave) {
        int i = askforleaveDao.updateAskforleave(askforleave);
        if (i >0){
            return true;
        }
        return false;
    }

    @Override
    public Askforleave getAskForById(int id) {
        return askforleaveDao.getAskForById(id);
    }


}
